//
//  GestureSettingView.swift
//  ezyform
//
//  Created by Moennig Q on 24/7/2022.
//  Copyright © 2022 Client.Solution Pty Ltd. All rights reserved.
//

import Foundation
import UIKit
class GestureSettingView: MeModelVCBaseView{
    
    let miniView = GestureMiniView()
    let tipLabel = BaseLabel()
    let gestureView = GestureLockView()
   
    override func setUpviews() {
        let contentView = UIView()
        contentView.backgroundColor = .white
        self.addSubview(contentView)
        contentView.snp.makeConstraints { make in
            make.top.equalTo(self.topBackView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        //min view
        contentView.addSubview(miniView)
        miniView.snp.makeConstraints { make in
            make.top.equalTo(50)
            make.width.height.equalTo(self.miniView.viewWidth)
            make.centerX.equalToSuperview()
        }
        //
        tipLabel.text = R.string.localizable.gestureDrawTip("\(self.gestureView.atLeastPoints)")//"Draw a gesture pattern with at least 5 points"
        tipLabel.textColor = UIColor(hexStr: "#292D32B3")
        tipLabel.setFont(R.font.interMedium(size: 14))
        tipLabel.numberOfLines = 0
        tipLabel.textAlignment = .center
        contentView.addSubview(tipLabel)
        tipLabel.snp.makeConstraints { make in
            make.top.equalTo(miniView.snp.bottom).offset(40)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.height.greaterThanOrEqualTo(0)
        }
        //gesture view
        contentView.addSubview(gestureView)
        gestureView.snp.makeConstraints { make in
            make.top.equalTo(tipLabel.snp.bottom).offset(30)
            make.left.right.equalToSuperview()
            make.height.equalTo(self.gestureView.gestureLockViewHeight)
        }
        //移除所有target，自定义自己的target
        self.backToPreBtn.removeTarget(nil, action: nil, for: .allEvents)
    }

    func dealErrorGesture(_ type: GestureResultType){
        switch type {
        case .redraw:
            self.tipLabel.text = R.string.localizable.gestureDrawNotmatchTip()//"Not match, Please draw it again"
            self.tipLabel.textColor = UIColor(hexStr: "#E94242")
        case .atLeast5:
            self.tipLabel.text = R.string.localizable.gestureDrawAtleastTip("\(self.gestureView.atLeastPoints)")//"At least \(self.gestureView.atLeastPoints) points, please redraw"
            self.tipLabel.textColor = UIColor(hexStr: "#E94242")
        case .toConfirmGesture:
            self.tipLabel.text = R.string.localizable.gestureDrawDrawagainTip()//"Draw the password pattern again"
            self.tipLabel.textColor = UIColor(hexStr: "#444444")

        default:
            break
        }
    }
}

